package com.blm.controller.rider;

import com.blm.common.Result;
import com.blm.service.RiderService;
import com.blm.util.SecurityUtil;
import com.blm.vo.RiderStatsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@Tag(name = "骑手相关API-数据统计", description = "骑手查看统计")
@RestController
@RequestMapping("/api/rider")
@SecurityRequirement(name = "bearerAuth")
public class RiderStatistisController {

    @Autowired
    private RiderService riderService;
    @Autowired
    private SecurityUtil securityUtil;


    @Operation(summary = "获取统计数据", description = "获取骑手的订单统计数据(当日/本周/本月)")
    @ApiResponse(responseCode = "200", description = "查询成功", content = @Content(mediaType = "application/json", schema = @Schema(implementation = RiderStatsVO.class)))
    @ApiResponse(responseCode = "400", description = "请求参数错误")
    @ApiResponse(responseCode = "401", description = "未授权或Token无效")
    @ApiResponse(responseCode = "404", description = "骑手不存在")
    @GetMapping("/stats")
    public Result<RiderStatsVO> getStats(@Parameter(description = "统计周期: day-日, week-周, month-月", schema = @Schema(allowableValues = {"day", "week", "month"})) @RequestParam(defaultValue = "day") String period) {
        Long userId = securityUtil.getCurrentUserId();
        RiderStatsVO stats = riderService.getStats(userId, period);
        return Result.success(stats);
    }
}
